home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 2
/
Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso
/
Aminet
/
comm
/
term
/
term34Source.lha
/
CopyPanel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-16
|
12KB
|
477 lines
/*
** CopyPanel.c
**
** Editing panel for configuration copying
**
** Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
** All Rights Reserved
*/
#include "termGlobal.h"
enum { GAD_SERIAL,GAD_MODEM,GAD_SCREEN,GAD_TERMINAL,GAD_EMULATION,
GAD_CLIPBOARD,GAD_CAPTURE,GAD_COMMANDS,GAD_MISC,GAD_PATHS,GAD_TRANSFER,
GAD_TRANSLATION,GAD_KEYMACROS,GAD_CURSORKEYS,GAD_FASTMACROS,GAD_COPYTOALL,
GAD_DEFAULT,GAD_ALL,GAD_CLEAR,GAD_USE,GAD_CANCEL };
enum { COPY_MAIN_CONFIG,COPY_DEFAULTS };
STATIC ULONG Bits = 0;
STATIC BYTE CopyMode = COPY_MAIN_CONFIG,
AllFileSettings = FALSE;
STATIC STRPTR CopyType[3];
STATIC struct Gadget *
CreateAllGadgets(struct Gadget **GadgetArray,struct Gadget **GadgetList)
{
struct Gadget *Gadget;
struct NewGadget NewGadget;
UWORD Counter = 0;
LocalizeString(CopyType,MSG_COPYPANEL_COPY_GLOBAL_CONFIG_MSG,MSG_COPYPANEL_COPY_GLOBAL_DEFAULTS_MSG);
SZ_SizeSetup(Window -> WScreen,&UserFont,TRUE);
memset(&NewGadget,0,sizeof(struct NewGadget));
if(Gadget = CreateContext(GadgetList))
{
WORD i,RightColumn;
SZ_AddLeftOffset(SZ_LeftOffsetDelta(MSG_COPYPANEL_SERIAL_GAD,MSG_COPYPANEL_COMMANDS_GAD));
RightColumn = SZ_LeftOffsetDelta(MSG_COPYPANEL_MISCELLANEOUS_GAD,MSG_COPYPANEL_TO_ALL_ENTRIES_GAD);
for(i = GAD_SERIAL ; i <= GAD_FASTMACROS ; i++)
{
NewGadget . ng_GadgetText = LocaleString(MSG_COPYPANEL_SERIAL_GAD + i - GAD_SERIAL);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = 0;
if(i == GAD_MISC)
{
SZ_AddLeftOffset(RightColumn);
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_NewColumn, TRUE,
GTCB_Checked, Bits & (1 << (i - GAD_SERIAL)),
TAG_DONE);
}
else
{
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
GTCB_Checked, Bits & (1 << (i - GAD_SERIAL)),
TAG_DONE);
}
}
NewGadget . ng_GadgetText = LocaleString(MSG_COPYPANEL_TO_ALL_ENTRIES_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
GTCB_Checked, FALSE,
TAG_DONE);
SZ_ResetMaxWidth();
SZ_UpdateMaxWidth(CYCLE_KIND,NULL,0,CopyType);
SZ_SetWidth(SZ_ResetMaxWidth());
NewGadget . ng_GadgetText = LocaleString(MSG_COPYPANEL_COPY_TYPE_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignBottom, TRUE,
SZ_AlignCentre, TRUE,
SZ_AlignExtra, TRUE,
GTCY_Labels, CopyType,
GTCY_Active, CopyMode,
TAG_DONE);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_COPYPANEL_ALL_GAD),0,NULL);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_COPYPANEL_CLEAR_GAD),0,NULL);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_USE_GAD),0,NULL);
SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_CANCEL_GAD),0,NULL);
SZ_SetWidth(SZ_ResetMaxWidth());
NewGadget . ng_GadgetText = LocaleString(MSG_COPYPANEL_ALL_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_Flags = PLACETEXT_IN;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignExtra, TRUE,
SZ_AlignLeft, TRUE,
SZ_AlignBottom, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_COPYPANEL_CLEAR_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignRight, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_USE_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignLeft, TRUE,
SZ_AlignBottom, TRUE,
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_CANCEL_GAD);
NewGadget . ng_GadgetID = Counter;
GadgetArray[Counter] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
SZ_Adjust, TRUE,
SZ_AutoWidth, TRUE,
SZ_AlignRight, TRUE,
TAG_DONE);
}
return(Gadget);
}
STATIC VOID __regargs
CopyConfig(struct Configuration *MyConfig,BYTE Part)
{
STATIC LONG TypeMappings[15][2] =
{
GAD_SERIAL, PREF_SERIAL,
GAD_MODEM, PREF_MODEM,
GAD_SCREEN, PREF_SCREEN,
GAD_TERMINAL, PREF_TERMINAL,
GAD_EMULATION, PREF_EMULATION,
GAD_CLIPBOARD, PREF_CLIP,
GAD_CAPTURE, PREF_CAPTURE,
GAD_COMMANDS, PREF_COMMAND,
GAD_MISC, PREF_MISC,
GAD_PATHS, PREF_PATH,
GAD_TRANSFER, PREF_TRANSFER,
GAD_TRANSLATION, PREF_FILE,
GAD_KEYMACROS, PREF_FILE,
GAD_CURSORKEYS, PREF_FILE,
GAD_FASTMACROS, PREF_FILE
};
LONG i,PrefType;
APTR Data;
for(i = 0 ; i < 15 ; i++)
{
if(Part == TypeMappings[i][0])
{
PrefType = TypeMappings[i][1];
break;
}
}
Data = GetConfigEntry(MyConfig,PrefType);
if(CopyMode == COPY_MAIN_CONFIG)
{
if(CreateConfigEntry(MyConfig,PrefType))
{
if(!Data)
ResetConfigEntry(MyConfig,PrefType,FALSE);
switch(Part)
{
case GAD_SERIAL:
memcpy(MyConfig -> SerialConfig,Config -> SerialConfig,sizeof(struct SerialSettings));
break;
case GAD_MODEM:
memcpy(MyConfig -> ModemConfig,Config -> ModemConfig,sizeof(struct ModemSettings));
break;
case GAD_SCREEN:
memcpy(MyConfig -> ScreenConfig,Config -> ScreenConfig,sizeof(struct ScreenSettings));
break;
case GAD_TERMINAL:
memcpy(MyConfig -> TerminalConfig,Config -> TerminalConfig,sizeof(struct TerminalSettings));
break;
case GAD_EMULATION:
memcpy(MyConfig -> EmulationConfig,Config -> EmulationConfig,sizeof(struct EmulationSettings));
break;
case GAD_CLIPBOARD:
memcpy(MyConfig -> ClipConfig,Config -> ClipConfig,sizeof(struct ClipSettings));
break;
case GAD_CAPTURE:
memcpy(MyConfig -> CaptureConfig,Config -> CaptureConfig,sizeof(struct CaptureSettings));
break;
case GAD_COMMANDS:
memcpy(MyConfig -> CommandConfig,Config -> CommandConfig,sizeof(struct CommandSettings));
break;
case GAD_MISC:
memcpy(MyConfig -> MiscConfig,Config -> MiscConfig,sizeof(struct MiscSettings));
break;
case GAD_PATHS:
memcpy(MyConfig -> PathConfig,Config -> PathConfig,sizeof(struct PathSettings));
break;
case GAD_TRANSFER:
memcpy(MyConfig -> TransferConfig,Config -> TransferConfig,sizeof(struct TransferSettings));
break;
case GAD_TRANSLATION:
strcpy(MyConfig -> FileConfig -> TranslationFileName,Config -> FileConfig -> TranslationFileName);
break;
case GAD_KEYMACROS:
strcpy(MyConfig -> FileConfig -> MacroFileName,Config -> FileConfig -> MacroFileName);
break;
case GAD_CURSORKEYS:
strcpy(MyConfig -> FileConfig -> CursorFileName,Config -> FileConfig -> CursorFileName);
break;
case GAD_FASTMACROS:
strcpy(MyConfig -> FileConfig -> FastMacroFileName,Config -> FileConfig -> FastMacroFileName);
break;
}
}
}
else
{
if(Data && (PrefType != PREF_FILE || AllFileSettings))
DeleteConfigEntry(MyConfig,PrefType);
}
}
BYTE
CopyPanel(struct Configuration *MyConfig,BYTE Selective)
{
struct Window *PanelWindow;
struct Gadget *GadgetList;
struct Gadget *GadgetArray[GAD_CANCEL + 1];
BYTE MadeChanges = FALSE;
if(CreateAllGadgets(GadgetArray,&GadgetList))
{
if(PanelWindow = OpenWindowTags(NULL,
WA_Left, GetScreenLeft(Window) + (GetScreenWidth(Window) - SZ_GetWindowWidth()) / 2,
WA_Top, GetScreenTop(Window) + (GetScreenHeight(Window) - SZ_GetWindowHeight()) / 2,
WA_Width, SZ_GetWindowWidth(),
WA_Height, SZ_GetWindowHeight(),
WA_Activate, TRUE,
WA_DragBar, TRUE,
WA_DepthGadget, TRUE,
WA_RMBTrap, TRUE,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_CustomScreen,Window -> WScreen,
WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY | IDCMP_RAWKEY | BUTTONIDCMP | CHECKBOXIDCMP,
WA_Title, LocaleString(MSG_COPYPANEL_COPY_CONFIG_TXT),
TAG_DONE))
{
struct IntuiMessage *Massage;
ULONG IClass,Code;
struct Gadget *Gadget;
BYTE Terminated = FALSE;
LONG i;
GuideContext(CONTEXT_COPY);
PushWindow(PanelWindow);
AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
GT_RefreshWindow(PanelWindow,NULL);
if(!MyConfig)
{
GT_SetGadgetAttrs(GadgetArray[GAD_COPYTOALL],PanelWindow,NULL,
GTCB_Checked, TRUE,
GA_Disabled, TRUE,
TAG_DONE);
}
ClrSignal(SIG_BREAK);
while(!Terminated)
{
if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
break;
while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
{
IClass = Massage -> Class;
Code = Massage -> Code;
Gadget = (struct Gadget *)Massage -> IAddress;
GT_ReplyIMsg(Massage);
KeySelect(GadgetArray,GAD_CANCEL,Code,PanelWindow,&Gadget,&IClass,&Code);
if(IClass == IDCMP_CLOSEWINDOW)
Terminated = TRUE;
if(IClass == IDCMP_GADGETUP)
{
switch(Gadget -> GadgetID)
{
case GAD_ALL:
for(i = GAD_SERIAL ; i <= GAD_FASTMACROS ; i++)
{
GT_SetGadgetAttrs(GadgetArray[i],PanelWindow,NULL,
GTCB_Checked, TRUE,
TAG_DONE);
}
break;
case GAD_CLEAR:
for(i = GAD_SERIAL ; i <= GAD_FASTMACROS ; i++)
{
GT_SetGadgetAttrs(GadgetArray[i],PanelWindow,NULL,
GTCB_Checked, FALSE,
TAG_DONE);
}
break;
case GAD_DEFAULT:
CopyMode = Code;
break;
case GAD_USE:
Bits = NULL;
if(SZ_GetChecked(GadgetArray[GAD_COPYTOALL]))
{
LONG j;
AllFileSettings = TRUE;
for(i = GAD_TRANSLATION ; i <= GAD_FASTMACROS ; i++)
AllFileSettings &= SZ_GetChecked(GadgetArray[i]);
if(Selective)
{
for(i = GAD_SERIAL ; i <= GAD_FASTMACROS ; i++)
{
if(SZ_GetChecked(GadgetArray[i]))
{
for(j = 0 ; j < NumPhoneEntries ; j++)
{
if(Phonebook[j] -> Count != -1)
CopyConfig(Phonebook[j] -> Config,i);
}
Bits |= (1 << (i - GAD_SERIAL));
MadeChanges = TRUE;
}
}
}
else
{
for(i = GAD_SERIAL ; i <= GAD_FASTMACROS ; i++)
{
if(SZ_GetChecked(GadgetArray[i]))
{
for(j = 0 ; j < NumPhoneEntries ; j++)
CopyConfig(Phonebook[j] -> Config,i);
Bits |= (1 << (i - GAD_SERIAL));
MadeChanges = TRUE;
}
}
}
}
else
{
if(MyConfig)
{
for(i = GAD_SERIAL ; i <= GAD_FASTMACROS ; i++)
{
if(SZ_GetChecked(GadgetArray[i]))
{
CopyConfig(MyConfig,i);
Bits |= (1 << (i - GAD_SERIAL));
MadeChanges = TRUE;
}
}
}
}
Terminated = TRUE;
break;
case GAD_CANCEL:
Terminated = TRUE;
break;
}
}
}
}
RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
PopWindow();
CloseWindow(PanelWindow);
}
FreeGadgets(GadgetList);
}
return(MadeChanges);
}